package com.example.leetcode;

/**
 * 猜数字大小
 */
public class Demo0374 {

    public static int RESULT=45;

    public static void main(String[] args) {
        System.out.println(guessNumber(300));
    }

    public static int guessNumber(int n) {
        int left=1,right=n;
        while (left<right){
            int mid=left+(right-left)/2;
            if (guess(mid)<=0){
                right=mid;
            }else {
                left=mid+1;
            }
        }
        return left;
    }

    public static int guess(int mid){
        return mid>RESULT?-1:(mid<RESULT?1:0);
    }


}
